package com.yellowpage.ca.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.dao.BaseDaoHibernateImpl;
import com.yellowpage.white.dao.QueryAssistantSQL;

import com.yellowpage.ca.data.Dictionary;

public class DictionaryDaoImpl extends BaseDaoHibernateImpl<Dictionary, Long>
		implements DictionaryDao {

	public DictionaryDaoImpl() {
		super(Dictionary.class);
	}

	@Override
	public List<Dictionary> getByDictType(String dictType) {
		return getObjectListByConditions("from Dictionary where dict_type=?",
				new Object[] { dictType });
	}

	@Override
	public Dictionary getByDictValueAndDictType(String dictValue,
			String dictType) {
		List<Dictionary> dictList = getObjectListByConditions(
				"from Dictionary where dict_type=? and dict_value=?",
				new Object[] { dictType, dictValue });
		return dictList == null || dictList.isEmpty() ? null : dictList.get(0);
	}

	@Override
	public List<String> getDistinctDictTypes() {
		List<String> dictTypes = new ArrayList<String>();

		QueryAssistantSQL sqlAssistant = newQueryAssistantSQL("select distinct dict_type from CA_DICTIONARY ");
		List<Map> resultList = sqlAssistant.query(getConnection(), null);

		for (Map map : resultList) {
			dictTypes.add((String) map.get("DICT_TYPE"));
		}

		return dictTypes;
	}

}